<template>
  <div>
    <!-- 卡片视图 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="10">
          <!-- 搜索框 -->
          <el-input
            placeholder="请输入内容"
            v-model="search"
            style="width: 200px"
          >
          </el-input>
          <el-button
            style="margin-left: 5rem"
            icon="el-icon-document-add"
            type="primary"
            @click="handleAdd"
            >添加</el-button
          >
          <el-button
            icon="el-icon-refresh"
            type="primary"
            @click="handleRefresh"
            >刷新</el-button
          >
        </el-col>
      </el-row>
      <br />
      <!-- 用户列表区域 -->
      <el-table
        :data="
          tableData.filter(
            (data) =>
              !search || data.name.toLowerCase().includes(search.toLowerCase())
          )
        "
        style="width: 100%"
        :header-cell-style="{ textAlign: 'center' }"
        :cell-style="{ textAlign: 'center' }"
      >
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="商品名称">
                <span>{{ props.row.name }}</span>
              </el-form-item>
              <el-form-item label="所属店铺">
                <span>{{ props.row.shop }}</span>
              </el-form-item>
              <el-form-item label="商品 ID">
                <span>{{ props.row.id }}</span>
              </el-form-item>
              <el-form-item label="店铺 ID">
                <span>{{ props.row.shopId }}</span>
              </el-form-item>
              <el-form-item label="商品分类">
                <span>{{ props.row.category }}</span>
              </el-form-item>
              <el-form-item label="店铺地址">
                <span>{{ props.row.address }}</span>
              </el-form-item>
              <el-form-item label="商品描述">
                <span>{{ props.row.desc }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="图片"></el-table-column>
        <el-table-column label="商品 ID" prop="id"> </el-table-column>
        <el-table-column label="商品名称" prop="name"> </el-table-column>
        <el-table-column label="描述" prop="desc"> </el-table-column>
        <el-table-column prop="price" label="商品价格(元)"></el-table-column>
        <el-table-column prop="number" label="商品数量"> </el-table-column>
        <el-table-column label="是否上架">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.isEnable"
              @change="change(scope.$index, scope.row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="createtime" label="创建时间">
          <template slot-scope="scope">
            {{ scope.row.createtime }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              circle
              size="small"
              @click="showEditDialog(scope.$index, scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[10, 15, 30, 50]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [
        {
          id: "12987122",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
          price: "12",
          number: 13456,
          createtime: "2020-12-4",
          isEnable: false,
        },
        {
          id: "12987123",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
          price: "12",
          number: 13456,
          createtime: "2020-12-4",
          isEnable: false,
        },
        {
          id: "12987125",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
          price: "12",
          number: 13456,
          createtime: "2020-12-4",
          isEnable: false,
        },
        {
          id: "12987126",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
          price: "12",
          number: 13456,
          createtime: "2020-12-4",
          isEnable: false,
        },
      ],

      search: "",
      queryInfo: {
        //   查询搜索参数
        query: "",
        // 当前显示多少条默认
        pagesize: 10,
        // 当前页码值，默认第一页
        pagenum: 1,
      },

      total: 0,
    };
  },
  created() {
    // this.getGoodsList()
  },
  methods: {
    //   根据分页获取对应的商品列表
    // async getGoodsList () {
    //   const { data: res } = await this.$http.get('goods', { params: this.queryInfo })
    //   console.log(res)
    //   if (res.meta.status !== 200) {
    //     return this.$message.error('获取商品信息失败')
    //   }
    //   this.goodslist = res.data.goods
    //   console.log(this.goodslist)
    //   this.total = res.data.total
    // },
    handleSizeChange() {
      // this.queryInfo.pagesize = newsize
      // this.getGoodsList()
    },
    // 监听页码值改变的事件
    handleCurrentChange() {
      // this.queryInfo.pagenum = newPage
      // this.getGoodsList()
    },
    //刷新
    handleRefresh() {
      location.reload();
    },

    //编辑
    showEditDialog(index, row) {
      console.log(index, row);
      console.log(index);
    },
    //添加
    handleAdd() {
      this.$router.push("/StoreManagement/StoreCommodityAdd");
    },
  },
};
</script>
<style  scoped>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
